<!--
 * @Author: your name
 * @Date: 2021-09-21 14:08:57
 * @LastEditTime: 2021-09-26 11:17:59
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \product-display\src\page\operate\login.vue
-->
<template>
  <div class="login operateContent">
    <h1 class="pageTitle">后台管理</h1>
    <div class="from">
      <p class="fromLabel">用户名:</p>
      <el-input v-model="name" placeholder="请输入用户名"></el-input>
      <p class="fromLabel">密码:</p>
      <el-input v-model="passWard" placeholder="请输入密码" show-password></el-input>
      <el-button class="buttonSubmit" :disabled="!name || !passWard" @click="login">登录</el-button>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Login',
  data () {
    return {
      name: '',
      passWard: ''
    }
  },
  methods: {
    login () {
      if (this.name === 'admin' && this.passWard === 'admin123!') {
        localStorage.setItem('token', encodeURIComponent(JSON.stringify({
          time: new Date().getTime(),
          name: this.name
        })))
        const path = localStorage.getItem('loginFromUrl') || '/operate/product/list'
        localStorage.removeItem('loginFromUrl')
        this.$router.push({
          path
        })
      } else {
        this.$message('账号或密码错误')
        this.passWard = ''
      }
    }
  }
}
</script>

<style lang="less" scoped>
.login {
  background: #eee;
  .pageTitle {
    padding-top: 100px;
    text-align: center;
  }
  .from {
    position: absolute;
    bottom: 45%;
    right: 50%;
    margin-right: -100px;
    padding: 20px;
    width: 200px;
    background: #fff;
    border-radius: 10px;
    box-shadow: #eee;
    .fromLabel {
      line-height: 30px;
      color: #999
    }
    .buttonSubmit {
      margin-top: 20px;
    }
  }
}
</style>
